package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.example.entity.Order;
import com.example.service.OrderService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class OrderController {
	@Resource
	private OrderService orderService;

	@GetMapping("/create_order")
	public String createOrder(Integer orderId, Integer memberId, Integer goodsId, Integer points, Integer quantity)
			throws JsonProcessingException {
		Map<String, Object> result = new HashMap<>();
		Order order = orderService.createOrder(orderId, memberId, goodsId, points, quantity);
		log.info("create_order: {}", JSON.toJSON(order));
		result.put("code", "0");
		result.put("message", "create order success");
		return new ObjectMapper().writeValueAsString(result);
	}
}
